package cn.source.system.controller;

import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.core.page.TableDataInfo;
import cn.source.common.enums.BusinessType;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.system.domain.DeyuDevice;
import cn.source.system.service.IDeyuDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备信息Controller
 *
 * @author deyucare.com
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/deyu/device")
public class DeyuDeviceController extends BaseController
{
    @Autowired
    private IDeyuDeviceService deyuDeviceService;

    /**
     * 查询设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('deyu:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeyuDevice deyuDevice)
    {
        startPage();
        List<DeyuDevice> list = deyuDeviceService.selectDeyuDeviceList(deyuDevice);
        return getDataTable(list);
    }

    /**
     * 获取设备信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(deyuDeviceService.selectDeyuDeviceById(id));
    }

    /**
     * 新增设备信息
     */
    @PreAuthorize("@ss.hasPermi('deyu:device:add')")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeyuDevice deyuDevice)
    {
        return toAjax(deyuDeviceService.insertDeyuDevice(deyuDevice));
    }

    /**
     * 修改设备信息
     */
    @PreAuthorize("@ss.hasPermi('deyu:device:edit')")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeyuDevice deyuDevice)
    {
        return toAjax(deyuDeviceService.updateDeyuDevice(deyuDevice));
    }

    /**
     * 删除设备信息
     */
    @PreAuthorize("@ss.hasPermi('deyu:device:remove')")
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deyuDeviceService.deleteDeyuDeviceByIds(ids));
    }

    /**
     * 导出设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('deyu:device:export')")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeyuDevice deyuDevice)
    {
        List<DeyuDevice> list = deyuDeviceService.selectDeyuDeviceList(deyuDevice);
        ExcelUtil<DeyuDevice> util = new ExcelUtil<DeyuDevice>(DeyuDevice.class);
        util.exportExcel(response, list, "设备信息数据");
    }
}
